export default {
  getItem(key) {
    try {
      return uni.getStorageSync(key);
    } catch (e) {
      console.log('uniStorage get', e);
      return null;
    }
  },
  setItem(key, data) {
    uni.setStorageSync(key, data);
  },
  getInfo() {
    return uni.getStorageInfoSync();
  },
  removeItem(key) {
    uni.removeStorageSync(key);
  },
  clear() {
    uni.clearStorageSync();
  },
  setStoreItem(storeName, key, data) {
    const itemInfo = this.getItem(storeName);
    if (!itemInfo) {
      this.setItem(storeName, {
        [key]: data,
      });
    } else {
      this.setItem(storeName, {
        ...JSON.parse(itemInfo),
        [key]: data,
      });
    }
  },
  getStoreItem(storeName, key) {
    const itemInfo = this.getItem(storeName);
    if (!itemInfo) return itemInfo;
    try {
      return JSON.parse(itemInfo)[key];
    } catch (e) {
      console.log('uniStorage getStoreItem err', e);
      return null;
    }
  },
};
